package com.huanming.dsjc.modular.goods.controller;

import com.huanming.dsjc.common.controller.BaseController;
import com.huanming.dsjc.modular.goods.dao.ShipcompanyMapper;
import com.huanming.dsjc.modular.goods.entity.ShipCompany;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;

import java.util.List;

/**
 * 物流公司控制器
 *
 * @author xufei
 * @Date 2018-01-31 18:30:01
 */
@Controller
@RequestMapping("/shipcompany")
public class ShipcompanyController extends BaseController {

    private String PREFIX = "/goods/shipcompany/";

    @Autowired
    private ShipcompanyMapper shipcompanyMapper;

    /**
     * 跳转到物流公司首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "shipcompany.html";
    }

    /**
     * 跳转到添加物流公司
     */
    @RequestMapping("/shipcompany_add")
    public String shipcompanyAdd() {
        return PREFIX + "shipcompany_add.html";
    }

    /**
     * 跳转到修改物流公司
     */
    @RequestMapping("/shipcompany_update/{shipcompanyId}")
    public String shipcompanyUpdate(@PathVariable Integer shipcompanyId, Model model) {
        ShipCompany shipcompany = shipcompanyMapper.selectById(shipcompanyId);
        model.addAttribute("shipcompany",shipcompany);
        return PREFIX + "shipcompany_edit.html";
    }

    /**
     * 获取物流公司列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
        List<ShipCompany> list = this.shipcompanyMapper.list(condition);
        return list;
    }

    /**
     * 新增物流公司
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(ShipCompany shipCompany) {
        this.shipcompanyMapper.insert(shipCompany);
        return super.SUCCESS_TIP;
    }

    /**
     * 删除物流公司
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(Integer shipcompanyId) {
        this.shipcompanyMapper.deleteById(shipcompanyId);
        return SUCCESS_TIP;
    }


    /**
     * 修改物流公司
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(ShipCompany shipcompany) {
        this.shipcompanyMapper.updateById(shipcompany);
        return super.SUCCESS_TIP;
    }

    /**
     * 物流公司详情
     */
    @RequestMapping(value = "/detail")
    @ResponseBody
    public Object detail() {
        return null;
    }
}
